# -*- coding: utf-8 -*-
"""
Created on Tue May 05 15:22:35 2015

@author: zhaoxp
"""

#firstly you should install VC++ compiler VCForPython27.msi and then install it
import paramiko

"""
connect remote linux server and run command and return command result
"""
def ssh_run_command(hostname,username,password,command):
    s=paramiko.SSHClient()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect(hostname = hostname,username=username, password=password)
    stdin,stdout,stderr=s.exec_command(command,timeout=20)
    #print(type(stdout))
    #print(dir(stdout))
    return stdout.readlines()

if __name__=='__main__':
    print("test ssh connection... start")
    command="df -h"
    result=ssh_run_command("10.99.110.83","wcadmin","******",command)
    for i in result:
        print(i.replace('\n',''))
    #rlist=result.split('\n')
    #print(type(result))
    #print(type(rlist))
    #print(result)
    #print(rlist)
    print("test ssh connection... end")
